<script setup lang="ts">
import { onLaunch, onShow, onHide, onShareAppMessage, onShareTimeline } from "@dcloudio/uni-app";
import { storeToRefs } from "pinia";
import { useAppStore } from "./store/app";
import { useChatStore } from "./store/chat";
import { useCommonStore } from "./store/common";
import { userLoginStore } from "./store/userLogin";
import { useRunInfoStore } from "./store/runInfo"
const useCommonData = useCommonStore()
const useChatData = useChatStore()
const useAppData = useAppStore()
const userLoginData = userLoginStore()
const useRunInfoData = useRunInfoStore()

onLaunch((options) => {
  console.log("App Launch", options);
  let optionsSync = uni.getLaunchOptionsSync()
  console.log("optionsSync", decodeURIComponent(optionsSync.query.scene), decodeURIComponent(optionsSync.query.scene).split("="))
  if (optionsSync?.query?.shareType === "circle" && optionsSync?.scene === 1155 && !optionsSync?.path.includes("/chat/chat")) {
    uni.reLaunch({
      url: '/pages/chat/chat',
    });
  }
  useChatData.initPresetQuestion()
  useRunInfoData.setIsRuning(false)
  // useRunInfoData.getConfigList()
});
onShow((options) => {
  console.log("APP onShow", options)
  console.log("useRunInfoData", useRunInfoData.isRuning, useRunInfoData.initStatus)
  let pages = getCurrentPages()
  let optionsSync = uni.getLaunchOptionsSync()
  if (useRunInfoData.isRuning) {
    if (!options || !options.path || !options.path.includes("pages/index/index")) {
      useRunInfoData.setInitStatus(false)
      uni.reLaunch({
        url: '/pages/index/index',
      });
    }
  } else {
    if (optionsSync?.scene === 1154) {
      uni.showToast({
        title: "请点击底部'前往小程序按钮'体验更多功能",
        icon: "none"
      })
    }
  }
  useAppData.getTitleHeight()
  useAppData.getAppSize()
  // useCommonData.handleShare()
});
onHide(() => {
  console.log("App Hide");
});
</script>
<style>
@import './common/uni.css';
@import './common/main.css';
</style>
